﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;

namespace IBRx {
	public abstract class BaseIBError : ServerConnectionResponse {
		abstract public int ErrorId { get; protected set; }

		abstract public string ErrorMessage { get; protected set; }

		abstract public int ErrorCode { get; protected set; }
	}

	public class StrError : BaseIBError {
		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public StrError(string msg) {
			this.ErrorId = -1;
			this.ErrorMessage = msg;
			this.ErrorCode = -1;
		}

		public override int ErrorId { get; protected set; }

		public override string ErrorMessage { get; protected set; }

		public override int ErrorCode { get; protected set; }
	}

	public class IBExError : BaseIBError {
		private readonly Exception e;

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public IBExError(Exception e) {
			this.ErrorId = 0;
			this.ErrorMessage = e.ToString();
			this.ErrorCode = 0;
			this.ExceptionObject = e;
		}

		public override int ErrorId { get; protected set; }

		public override string ErrorMessage { get; protected set; }

		public override int ErrorCode { get; protected set; }

		public Exception ExceptionObject { get; protected set; }
	}

	public class IBStandardizedError : BaseIBError {
		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public IBStandardizedError(int id, int errorCode, string errorMsg) {
			this.ErrorId = id;
			this.ErrorMessage = errorMsg;
			this.ErrorCode = errorCode;
		}

		public override int ErrorId { get; protected set; }

		public override string ErrorMessage { get; protected set; }

		public override int ErrorCode { get; protected set; }
	}
}
